package com.software.car.service;

import com.software.car.common.enums.ResultEnum;
import com.software.car.common.enums.RoleEnum;
import com.software.car.common.exception.MyException;
import com.software.car.common.utils.JwtUtil;
import com.software.car.common.utils.SnowflakeIdGenerator;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 *
 * 提权码开关
 *
 * @Author 魔法はまだ解けない
 * @Date 2021/3/24
 */
@Service
public class FeaturesService {

    private boolean code=false;

    HashMap<String,Integer> secret = new HashMap<>();

    public Integer getRole(String secretKey){
        if(code){
            Integer integer = secret.get(secretKey);
            return integer;
        }
        throw new MyException(ResultEnum.CLOSE);
    }

    //获取秘钥
    public HashMap<String,Integer> getSecret(){
        if(code){
            //放入两个秘钥
            return secret;
        }else {
            return null;
        }
    }

    /**
     * 开启提权
     * @return
     */
    public boolean close() {
        if(code){
            secret.clear();
            code =false;
        }
        return code;
    }

    /**
     * 开启提权
     * @return
     */
    public boolean open() {
        if(!code){
            code =true;
            //生成秘钥1
            String key1 = SnowflakeIdGenerator.getId();
            String key2 = SnowflakeIdGenerator.getId();
            secret.put(key1,2);
            secret.put(key2,4);
        }
        return code;
    }
}
